<template>
  <el-dialog
      title="应用上架"
      :visible.sync="visible"
      width="500px"
      class="sale-app-dlg"
      :before-close="handleClose">
    <div class="radio-wrapper">
      <el-radio v-model="isNew" :label="true">上架新商品</el-radio>
    </div>
    <div class="radio-wrapper">
      <el-radio v-model="isNew" :label="false">更新商品</el-radio>
      <el-select v-model="selectedGood" :disabled="isNew" placeholder="请选择应用名称或商品编号">
        <el-option
          v-for="item in goodsOptions"
          :key="item.goodsId"
          :label="item.goodsId + '-' + item.goodsName"
          :value="item.goodsId">
        </el-option>
      </el-select>
    </div>
    <span slot="footer" class="dialog-footer">
      <el-button type="primary" @click="onOK">确 定</el-button>
      <el-button @click="visible = false">取 消</el-button>
    </span>
  </el-dialog>
</template>

<script>
  import { openWin, stringifyParams } from "../../../utils/tool";

  export default {
    name: "saleAppDialog",
    data() {
      return {
        visible: false,
        isNew: true,
        selectedGood: '',
        goodsOptions: []
      }
    },

    methods: {
      /**
       * 弹出上架对话框
       * @param putOnParams {Object} url调账参数对象
       * @param goodsOptions {Object} 下拉列表
       */
      pop(putOnParams, goodsOptions) {
        this.isNew = true;
        this.selectedGood = '';
        this.putOnParams = putOnParams;
        this.goodsOptions = goodsOptions;
        this.visible = true;
      },

      handleClose(done) {
        done();
      },

      onOK() {
        if (!this.isNew && !this.selectedGood) {
          this.$msgbox({
            title: '提示',
            message: '应用名称或商品编号为必填项，请选择',
            type: 'warning',
            center: true
          }).then(action => {
          }).catch(reason => {
          });
        } else {
          const search = {
            goods_type: this.putOnParams.goodsType,
            goods_name: this.putOnParams.goodsName,
            designer: this.putOnParams.designer,
            designer_org: this.putOnParams.designerOrg,
            goods_file: this.putOnParams.goodsFile,
            version_no: this.putOnParams.versionNo
          };

          if (!this.isNew) {
            search.step = 2;
          }

          openWin(
            'https://testcloud.seeyon.com/admin/goods/addGoodsNew?' + stringifyParams(search),
            '上架商品',
            40,
            30
          );
          this.visible = false;
        }
      }
    }
  }
</script>

<style lang="scss">
  .sale-app-dlg {
    .el-dialog__body {
      padding: 30px 50px;
    }

    .el-select {
      width: 290px;
    }

    .el-input__inner {
      padding-left: 12px;
      height: 40px;
      line-height: 1;
      font-size: 14px;
      box-sizing: border-box;
    }

    .radio-wrapper {
      margin-bottom: 26px;

      &:last-child {
        margin-bottom: 0;
      }
    }
  }
</style>